/**
 * 
 */
package org.yt.dao.common;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.yt.dao.base.DefaultDao;
import org.yt.domain.Users;

/**
 * @author houji
 * 2010-9-1
 * 
 */
public class LoginDao extends DefaultDao {
	private final static Logger log = Logger.getLogger(LoginDao.class);
	
	public List<Users> checkUser(Users users){
		List<Users> result = new ArrayList<Users>();
		String username = users.getUsername();
		String password = users.getPassword();
		String sql = "select * from b_users where username = '"+username+"'" +
				" and password = '"+password+"'";
		log.debug(sql);
		ResultSet rs = find(sql);
		
		try {
			while(rs.next()){
				Users obj = new Users();
				long id = rs.getLong("id");
				int age = rs.getInt("age");
				int sex = rs.getInt("sex");
				Date create_at = rs.getDate("create_at");
				obj.setId(id);
				obj.setAge(age);
				obj.setCreate_at(create_at);
				obj.setPassword(password);
				obj.setSex(sex);
				obj.setUsername(username);
				result.add(obj);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
}
